package com.fs.config;

import org.springframework.boot.SpringBootConfiguration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author yyds
 * @fileName MyWebmvcConfig
 * @date 2024/9/25 9:25
 * @description 解决跨域问题
 **/
@SpringBootConfiguration
public class MyWebmvcConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")//允许跨域路径
                //.allowedOrigins("*")//允许跨域的源头
                .allowedOriginPatterns("*")//允许跨域的源头,可以解析
                .allowedMethods("POST", "GET", "PUT", "DELETE", "OPTIONS")//允许跨域的请求方式
                .maxAge(60000)//超时最大时间
                .allowCredentials(true)//允许客户端发送cookie,为true就不能用allowedOrigins("*")
                .allowedHeaders("*");//允许携带头部信息
    }
}
